import 'package:auto_size_text/auto_size_text.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';

import '../../../dd_core/dd_config.dart';
import '../../../dd_models/dd_hive_works_model.dart';
import '../../../r.dart';

class DDVideoCard extends StatelessWidget {
  final HiveWorksModel model;
  final Function()? onMore;
  final Function()? onComment;
  final Function()? onLike;
  final Function()? onCollection;
  final Function()? onClick;

  DDVideoCard(
      {required this.model,
      this.onMore,
      this.onComment,
      this.onLike,
      this.onCollection,
      this.onClick});

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 550,
        padding: const EdgeInsets.only(top: 16.0),
        child: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
          double widgetWidth = constraints.maxWidth;
          return Stack(
            children: [
              Positioned.fill(
                child: Padding(
                  padding: const EdgeInsets.only(top: 0.0),
                  child: Image.asset(
                    R.assetsImagesVideo2,
                    fit: BoxFit.fill,
                  ),
                ),
              ),
              Positioned(
                child: Container(
                  child: Padding(
                    padding: const EdgeInsets.only(left: 0.0, right: 0, top: 0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(
                              left: 10.0, right: 14, top: 10),
                          child: Stack(children: [
                            Positioned(
                              child: GestureDetector(
                                onTap: () {},
                                child: Container(
                                  height: 410,
                                  width: widgetWidth,
                                  child: CachedNetworkImage(
                                    height: 410,
                                    width: widgetWidth,
                                    fit: BoxFit.fitWidth,
                                    imageUrl: model.middleThumbUrl ?? '',
                                    placeholder: (context, url) =>
                                        Placeholder(),
                                    errorWidget: (context, url, error) =>
                                        Placeholder(),
                                  ),
                                ),
                              ),
                            ),
                            Positioned(
                              top: 0,
                              left: 0,
                              right: 0,
                              bottom: 0,
                              child: Center(
                                child: IconButton(
                                  icon: Image.asset(
                                    R.assetsImagesHome19,
                                    color: Colors.white,
                                  ),
                                  onPressed: () {
                                    if (onClick != null) {
                                      this.onClick!();
                                    }
                                  },
                                ),
                              ),
                            ),
                            Row(
                              children: [
                                Spacer(),
                                IconButton(
                                  icon: Image.asset(R.assetsImagesHomeSecond2),
                                  onPressed: () {
                                    if (onMore != null) {
                                      this.onMore!();
                                    }
                                  },
                                ),
                              ],
                            ),
                          ]),
                        ),
                        SizedBox(height: 40),
                        Padding(
                          padding: const EdgeInsets.only(
                            left: 10.0,
                            right: 10,
                          ),
                          child: AutoSizeText(
                            model.description ?? '',
                            maxLines: 1,
                            minFontSize: 8,
                            style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 14,
                                color: Color(0xFF404040)),
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(
                            left: 10.0,
                            right: 8,
                          ),
                          child: Row(
                            children: [
                              ClipRRect(
                                borderRadius:
                                    BorderRadius.circular(16.0),
                                child: CachedNetworkImage(
                                  width: 32,
                                  height: 32,
                                  imageUrl: model.avatarUrl ?? '',
                                  placeholder: (context, url) => Placeholder(),
                                  errorWidget: (context, url, error) =>
                                      Placeholder(),
                                ),
                              ),
                              SizedBox(width: 10),
                              ConstrainedBox(
                                constraints: BoxConstraints(maxWidth: 140),
                                child: Text(
                                  model.nickname ?? '',
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontSize: 14),
                                  maxLines: 1,
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                              Spacer(),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  IconButton(
                                    icon: Image.asset(
                                      R.assetsImagesHomeSecond3,
                                    ),
                                    onPressed: () {
                                      if (onComment != null) {
                                        this.onComment!();
                                      }
                                    },
                                  ),
                                  IconButton(
                                    icon: Image.asset((model.myLikes ?? false)
                                        ? R.assetsImagesHomeSecond6
                                        : R.assetsImagesHomeSecond4),
                                    onPressed: () {
                                      if (onLike != null) {
                                        this.onLike!();
                                      }
                                    },
                                  ),
                                  IconButton(
                                    icon: model.myFollow ?? false
                                        ? Image.asset(R.assetsImagesHome71)
                                        : Image.asset(
                                            R.assetsImagesHomeSecond5),
                                    onPressed: () {
                                      if (onCollection != null) {
                                        this.onCollection!();
                                      }
                                    },
                                  )
                                ],
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          );
        }));
  }
}
